import unittest, requests

class Register(unittest.TestCase):

    # 注册成功
    def test_01(self):
        register = requests.post(
            url='http://10.59.9.14:7003/api/register',
            json={"username":"15523615656","password":"123456Aa"}
        )
        print(register.json())
        # 断言
        self.assertEqual(1, register.json()['status'])

    # 账号不符合运营商规范
    def test_02(self):
        register = requests.post(
            url='http://10.59.9.14:7003/api/register',
            json={"username":"11122223333","password":"123456Aa"}
        )
        print(register.json())
        # 断言
        self.assertIn('不正确', register.json()['info'])

    # 账号长度超出限制
    def test_03(self):
        register = requests.post(
            url='http://10.59.9.14:7003/api/register',
            json={"username":"155236151590","password":"123456Aa"}
        )
        print(register.json())
        # 断言
        self.assertIn('不正确', register.json()['info'])

    # 密码长度不符合6-18位字符
    def test_04(self):
        register = requests.post(
            url='http://10.59.9.14:7003/api/register',
            json={"username":"15523615159","password":"12345"}
        )
        print(register.json())
        # 断言
        self.assertEqual('密码长度请控制在6-18字符！', register.json()['info'])

    # 密码中包含中文
    def test_05(self):
        register = requests.post(
            url='http://10.59.9.14:7003/api/register',
            json={"username":"12312312311","password":"123456六"}
        )
        print(register.json())
        # 断言
        self.assertEqual(0, register.json()['status'])

    # 账号中包含英文
    def test_06(self):
        register = requests.post(
            url='http://10.59.9.14:7003/api/register',
            json={"username":"1552361575一","password":"123456Aa"}
        )
        print(register.json())
        # 断言
        self.assertEqual('您填写的手机号码不正确！', register.json()['info'])

    # 账号中包含英文
    def test_07(self):
        register = requests.get(
            url='http://10.59.9.14:7003/api/register',
            json={"username":"1552361575一","password":"123456Aa"}
        )
        print(register.json())
        self.assertEqual('ok', register.json()['info'])

    # 密码为空
    def test_08(self):
        register = requests.get(
            url='http://10.59.9.14:7003/api/register',
            json={"username":"15523615751","password":""}
        )
        print(register.json())
        self.assertEqual('ok', register.json()['info'])

    # 传入参数多一个
    def test_09(self):
        register = requests.get(
            url='http://10.59.9.14:7003/api/register',
            json={"username":"15523615751","password":"123456Aa","num":"123"}
        )
        print(register.json())
        self.assertNotIn('n', register.json()['info'])

    # 传入参数少一个
    def test_10(self):
        register = requests.get(
            url='http://10.59.9.14:7003/api/register',
            json={"password":"123456Aa"}
        )
        print(register.json())
        self.assertNotIn('n', register.json()['info'])